/**
 * 
 */
package com.zdy.im.tio.packets;



import com.sixeco.framework.common.api.ApiDesc;
import com.sixeco.framework.util.json.JsonUtils;
import com.zdy.im.core.ICommand;
import com.zdy.im.core.Status;
import com.zdy.im.tio.command.Command;
import org.tio.utils.json.Json;

import java.io.Serializable;
import java.util.Objects;

/**
 * 版本: [1.0]
 * 功能说明: 
 * @Author 作者 : zdy
 * @CreateDate 创建时间: 2021-02-30
 */
public class SocketResponseVo implements Serializable{
	
	protected static final long serialVersionUID = 1L;
	/**
	 * 响应状态码;
	 */
	@ApiDesc(value = "响应状态码;")
	protected Integer code;
	/**
	 * 响应状态信息提示;
	 */
	@ApiDesc(value = "响应状态信息提示;")
	protected String msg;
	/**
	 * 响应cmd命令码;
	 */
	@ApiDesc(value = "响应cmd命令码;")
	private ICommand command;

	/**
	 * 响应数据;
	 */
	@ApiDesc(value = "响应数据;;")
	protected Object data;

	public SocketResponseVo(){}

	public SocketResponseVo(ICommand command){
		this.command = command;
	}

	public SocketResponseVo(ICommand command, Object data){
		this(command);
		this.data = data;
	}

	public SocketResponseVo(ICommand command , Status status){
		this(status);
		this.command = command;
	}

	public SocketResponseVo(Status status){
		if(Objects.nonNull(status)){
			this.code = status.getCode();
			this.msg = status.getMsg();
		}
	}

	public SocketResponseVo(Integer code, String msg){
		this.code = code;
		this.msg = msg;
	}

	public Integer getCode() {
		return code;
	}

	public SocketResponseVo setCode(Integer code) {
		this.code = code;
		return this;
	}

	public String getMsg() {
		return msg;
	}

	public SocketResponseVo setMsg(String msg) {
		this.msg = msg;
		return this;
	}

	public ICommand getCommand() {
		return command;
	}

	public SocketResponseVo setCommand(Command command) {
		this.command = command;
		return this;
	}

	public Object getData() {
		return data;
	}

	public SocketResponseVo setData(Object data) {
		this.data = data;
		return this;
	}

	@Override
	public String toString() {
		return JsonUtils.toJson(this);
	}
	
	public byte[] toByte(){
		return Json.toJsonAboutNull(this).getBytes();
	}

}
